package com.yc.c110s2plyqnzf;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.yc.c110s2plyqnzf.util.DateConvertor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@SpringBootApplication
@MapperScan("com.yc.c110s2plyqnzf.mapper")
public class C110S2PlyQnzfApplication implements WebMvcConfigurer {

    public static void main(String[] args) {
        SpringApplication.run(C110S2PlyQnzfApplication.class, args);
    }

    @Override
    public void addFormatters(FormatterRegistry registry) {
        registry.addConverter(new DateConvertor());
    }

    @Value("${uploadDir}")
    private String uploadDir;
    // 静态资源映射
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        System.out.println(uploadDir);
        registry.addResourceHandler("/upload/**")
                .addResourceLocations(uploadDir);
    }

    // 分页拦截器
    @Bean
    public MybatisPlusInterceptor mpi(){
        MybatisPlusInterceptor mpi = new MybatisPlusInterceptor();
        mpi.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        return mpi;
    }
}
